package components{
	import components.flatline;
	import components.staff_lines;
	
	import mx.graphics.SolidColor;
	
	import spark.core.SpriteVisualElement;
	import spark.primitives.Ellipse;
	import spark.primitives.supportClasses.FilledElement;

	public class notes{
		
		[Bindable]
		private var _hstep:int;
		private var _notegrid:Array;
		public var _black:SolidColor = new SolidColor(0x000000, 1);
		public var _red:SolidColor = new SolidColor(0xFF0000,1);
		//[Bindable]
		//private var _boolgrid:Array;
		
		public function notes(wid:int, hi:int):void{
			_hstep = 7;
			_notegrid = new Array();

			for(var i:int=0; i<hi+2; i++){
				_notegrid[i] = new Array();
			}

			for(var j:int=0; j<(hi+2); j++){
				for(var k:int=0; k<wid; k++){
					if(j<hi){
						var elps:Ellipse = new Ellipse();
						//elps.y = j*30 + 250;
						if(j==0){
							elps.y = 315-_hstep*3;
						}else if(j==1){
							elps.y = 315;
						}
						else if(j==2){
							elps.y = 315+_hstep*3;
						}
						else if(j==3){
							elps.y = (315+_hstep*7)-1;
						}
						else if(j==4){
							elps.y = (315+_hstep*14)-4;
						}
						
						elps.x = k*40 + 100;
						elps.width = 18;
						elps.height = 12;
						elps.fill = _black;
						elps.visible = false;
						_notegrid[j].push(elps);
					}else{
						if(j==5){
							var ftln:flatline = new flatline();
							ftln.x = k*40 + 90;
							ftln.y = (315-_hstep*3)-5;
							ftln.visible = false;
							_notegrid[j].push(ftln);
						}
						else{
							var slns:staff_lines = new staff_lines();
							slns.x = k*40 + 96.4;
							slns.y = (315+_hstep*8)-2;
							slns.visible = false;
							_notegrid[j].push(slns);
						}
					}
				}
			}
		}
		public function getArray():Array{
			return _notegrid;
		}
		public function updateNotes(frac:int):void{
			for(var j:int=0; j<_notegrid.length; j++){
				_notegrid[j][0].visible = false;
				for(var k:int=1; k<_notegrid[j].length; k++){
					if(_notegrid[j][k].visible == true){
						_notegrid[j][k-1].visible = true;
						_notegrid[j][k].visible = false;
					}
				}
			}
			_notegrid[_notegrid.length-(frac+2)][_notegrid[0].length-1].visible = true;
			_notegrid[_notegrid.length-(frac+2)][_notegrid[0].length-1].fill = _red;
			if(_notegrid.length-(frac+2) == 0){
				_notegrid[5][_notegrid[0].length-1].visible = true;
			}else if(_notegrid.length-(frac+2) == 4){
				_notegrid[6][_notegrid[0].length-1].visible = true;
			}
		}
	}
}